import { Component, EventEmitter, Injector, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
import { STComponent } from '@delon/abc/st';
import { STComponentBase } from '@shared/itcore/components/st-component-base';
import { FilterGroup, FilterOperate, FilterRule } from '@shared/itcore/itcore.model';
import { ItcoreSTColumn } from '@shared/itcore/services/alain.types';

@Component({
  selector: 'itcore-function-view',
  template: `
    <div>
      <button nz-button (click)="st.reload()"><i nz-icon nzType="reload" theme="outline"></i>刷新</button>
    </div>
    <st
      #st
      [data]="ReadUrl"
      [columns]="columns"
      size="small"
      [req]="req"
      [res]="res"
      [(pi)]="request.PageCondition.PageIndex"
      [(ps)]="request.PageCondition.PageSize"
      [page]="page"
    ></st>
  `,
  styles: [],
})
export class FunctionViewComponent extends STComponentBase implements OnInit {
  @Input() ReadUrl: string;

  @ViewChild('st', { static: false }) st: STComponent;

  constructor(injector: Injector) {
    super(injector);
  }

  ngOnInit() {
    super.InitBase();
  }

  protected GetSTColumns(): ItcoreSTColumn[] {
    return [
      { title: '功能名称', index: 'Name' },
      { title: '功能类型', index: 'AccessType', type: 'tag', tag: this.alain.AccessTypeTags, width: 100 },
      { title: '区域', index: 'Area', width: 80 },
      { title: '控制器', index: 'Controller', width: 100 },
    ];
  }

  reload(filter: FilterGroup) {
    this.st.pi = 1;
    this.request.FilterGroup = filter;
    this.st.req.body = this.request;
    this.st.reload();
  }
}
